package grape.base.rest.role.mvc;

import grape.base.service.role.api.IRoleService;
import grape.base.service.role.po.Role;
import grape.common.rest.advice.DisableGRB;
import grape.common.rest.advice.DisableGRM;
import grape.common.rest.mvc.SuperController;
import grape.common.tools.ToolService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * Created by yangwei
 * Created at 2020/6/9 14:01
 */
@RestController
@RequestMapping("/base/role")
@ApiIgnore
@Api(tags = "仅供内部微服务调用")
public class RoleInnerController extends SuperController implements ToolService {


    @Autowired
    private IRoleService roleService;

    /**
     * 根据id获取角色
     * @param roleId
     * @return
     */
    @DisableGRM
    @DisableGRB
    @GetMapping(value = "inner/getRoleByRoleId")
    public Role getRoleByRoleId(String roleId){
        return roleService.getById(roleId);
    }

    /**
     * 根据ids 获取角色
     * @param roleIds
     * @return
     */
    @DisableGRM
    @DisableGRB
    @GetMapping(value = "inner/getRoleByRoleIds")
    public List<Role> getRoleByRoleIds(List<String> roleIds){
        return (List<Role>) roleService.listByIds(roleIds);
    }


    /**
     * 根据用户id获取角色
     * @param userId
     * @return
     */
    @DisableGRM
    @DisableGRB
    @GetMapping(value = "inner/getRoleByUserId")
    public List<Role> getRoleByUserId(String userId){
        return roleService.getByUserId(userId,null);
    }

}
